package cn.shadow.game.chess.CHnchess.chessman;


import cn.shadow.game.chess.CHnchess.board.Board;
import cn.shadow.game.chess.CHnchess.board.Position;
import cn.shadow.game.chess.CHnchess.board.Slash;
import cn.shadow.game.chess.CHnchess.type.Camp;
import cn.shadow.game.chess.CHnchess.type.ChessType;

public class Shi extends AbstractChess implements Slash {
    public Shi(Board board, Camp camp) {
        super(ChessType.SHI, board, camp);
    }

    private void addPoint(Position position) {
        if (position.isOverRanged()) {
            return;

        }
        if (!position.isInCenter()) {
            return;
        }
        Chess chess = position.getChess();
        if (chess != null) {
            if (chess.getCamp() == this.getCamp()) {
                return;
            }
        }
        canSetPosition.add(position);
        canAttackPosition.add(position);
    }

    /**
     * 左上
     */
    @Override
    public void addLeftUpPoint() {
        int row = this.getRow();
        int col = this.getCol();
        Position point = getBoard().getPoint(row - 1, col - 1);
        if (point != null) {
            addPoint(point);
        }
    }

    /**
     * 右上
     */
    @Override
    public void addRightUpPoint() {
        int row = this.getRow();
        int col = this.getCol();
        Position point = getBoard().getPoint(row - 1, col + 1);
        if (point != null) {
            addPoint(point);
        }
    }

    /**
     * 左下
     */
    @Override
    public void addLeftDownPoint() {
        int row = this.getRow();
        int col = this.getCol();
        Position point = getBoard().getPoint(row + 1, col - 1);
        if (point != null) {
            addPoint(point);
        }
    }

    /**
     * 右下
     */
    @Override
    public void addRightDownPoint() {
        int row = getRow();
        int col = getCol();
        Position point = getBoard().getPoint(row + 1, col + 1);
        if (point != null) {
            addPoint(point);
        }
    }
}
